package it.unibo.deis.lia.location;

//import java.util.StringTokenizer;

//import ekahauClient.util.AccessPoint;
//import ekahauClient.util.SignalQuality;
// Classe che definisce l'oggetto AP

public class BSS extends NamedLocationOss{
	
	private static final long serialVersionUID = 1L;
	
	private String mac;
	//private String ssid; //usiamo il nome in NamedLocationOss
	private int rssi,noise,channel;
	private long timestamp;
	
	private int encryption;
	public static int UNKNOWN_ENCRYPTION=-1;
	public static int NONE_ENCRYPTION=0;
	public static int WEP=1;
	public static int WPA=2;
	private String wepKey=null;
	private String wpaUsername=null;
	private String wpaPassword=null;
	
	private int type;
	public static int UNKNOWN_TYPE=-1;
	public static int INFRASTRUCTURE=0;
	public static int ADHOC=1;
	
	/*public BSS(String mac,int channel,String ssid,int rssi,int noise,long timestamp){
		this(mac,channel,ssid,rssi,noise,timestamp,BSS.UNKNOWN_TYPE,BSS.UNKNOWN_ENCRYPTION);
	}
	public BSS(String mac,int channel,String ssid,int rssi,int noise,long timestamp,int type){
		this(mac,channel,ssid,rssi,noise,timestamp,type,BSS.UNKNOWN_ENCRYPTION);
	}*/
	public BSS(String mac,int channel,String ssid,int rssi,int noise,long timestamp, int type, int encryption){
		//id,mac,""+channel,ssid,rssi,noise,timestamp
		super(mac,""+rssi);
		this.mac=mac;
		//this.ssid=ssid;
		super.setName(ssid);
		if(rssi>0)this.rssi=-rssi;
		else this.rssi=rssi;
		this.channel=channel;
		this.noise=noise;
		this.timestamp=timestamp;
		if(type==BSS.ADHOC || type==BSS.INFRASTRUCTURE){
			this.type=type;
		}
		else{
			this.type=BSS.UNKNOWN_TYPE;
		}
		if(encryption==BSS.NONE_ENCRYPTION || encryption==BSS.WEP || encryption==BSS.WPA){
			this.encryption=encryption;
		}
		else{
			this.encryption=BSS.UNKNOWN_ENCRYPTION;
		}
	}
		
	public String getMac(){
		return mac;
	}
	
	public String getEssid(){
		return super.getName();
	}
	
	public int getRssi(){
		return rssi;
	}
	
	public int getChannel(){
		return channel;
	}

	public long getTimestamp(){
		return timestamp;
	}
	
	public int getNoise(){
		return noise;
	}
	
	public int getType(){
		return type;
	}
	
	public int getEncryption(){
		return encryption;
	}
	
	public void setWEPKey(String newWEPKey){
		this.wepKey=newWEPKey;
	}
	public String getWEPKey(){
		return wepKey;
	}
	
	public void setWPAPair(String newWPAUsername, String newWPAPassword){
		this.wpaUsername=newWPAUsername;
		this.wpaPassword=newWPAPassword;
	}
	public String getWPAUsername(){
		return wpaUsername;
	}
	public String getWPAPassword(){
		return wpaPassword;
	}
	
	public String toString(){
		String typeString="UNKNOWN_TYPE";
		if(type==BSS.ADHOC){
			typeString="ADHOC";
		}
		else if(type==BSS.INFRASTRUCTURE){
			typeString="INFRASTRUCTURE";
		}
		
		String encryptionString="UNKNOWN_ENCRYPTION";
		if(encryption==BSS.NONE_ENCRYPTION){
			encryptionString="NONE_ENCRYPTION";
		}
		else if(encryption==BSS.WEP){
			encryptionString="WEP";
		}
		else if(encryption==BSS.WPA){
			encryptionString="WPA";
		}
		
		return 
			channel+";"+
			getMac()+";"+
			getEssid()+";"+
			getRssi()+";"+
			noise+";"+
			typeString+";"+
			encryptionString+";"+
			timestamp;
	}
}
